## -*- coding: utf-8 -*-
<%inherit file="/derived/section/section_base.html"/>
<%namespace file="/component/navigation.html" import="header_nav, rank_extra_lable" />
<%namespace file="/component/utils.html" import="*" />
<%namespace file="/component/post.html" import="display_comments, blog_info, blog_comments" />
<%!
    from pythonblog.service.section_service import get_section
%>
<div style="margin-top:16px;">
    <div class="crumbs rounded {top-right transparent}">
        您的位置:
        <% section = get_section(c.post.section_id) %>
        <a href="${h.url_for_home()}">首页</a>
        <span class="arrow">→</span>
        <a href="http://${h.home + h.get_path(c.menu, section.path, 1)}">${section.name}</a>
        <span class="arrow">→</span>
        ${link_for_post(c.post)}
    </div>
    <div>
        <div class="blog clearfix">
            <div id="blog_owner_logo" style="margin-right: 0px;">${link_for_user_logo(c.post.user)}</div>
            <div style="float: right;">
                ${digg(c.post)}
            </div>
            <div class="content" style="width: 490px;">
                <div class="title" style="padding-bottom: 18px;">
                    <div class="title_url">
                        ${link_for_post(c.post)}
                    </div>
                </div>
                <div class="blog_info" style="background-color: transparent; padding-left: 2px;">
                    ${blog_info(c.post, True)}
                </div>
            </div>
        </div>
        <div style="padding-left:9px;padding-right:10px;">
            ${h.literal(c.post.content)}
        </div>
        <div id="dig_bottom">
            ${digg_bottom(c.post)}
        </div>
        <div class="blog_comment" id="commentsWrapper" style="width:600px;">
            ${display_comments(c.comments)}
        </div>

        <div class="blog_comment" style="width:600px;">
            ${blog_comments()}
        </div>
    </div>
</div>

<%def name="head()">
${parent.head()}
${h.stylesheet_link(h.url_for('/css/post.css'))}
${h.javascript_link(h.url_for('/js/nicEdit.js'))}

<script type="text/javascript">
    var comment_content;
    var contentTextArea;
    $(document).ready(function() {
        contentTextArea = new nicEditor({maxHeight : 200,
            iconsPath : "${h.url_for('/js/nicEditorIcons.gif')}",
            buttonList : ['bold','italic','underline','left','center','right','ol','ul','fontSize','indent','outdent','image','link','unlink','forecolor']
        }).panelInstance('content');

        $('#btnSubmit').click(commentAdd);
    });

    function commentAdd()  {
        var data = contentTextArea.nicInstances[0].getContent();
        if ('<br>' == data.toLowerCase()) {
            data = '';
        }
        if (data == '') {
            var l = $('<label class="error">请提供您的评论</label>');
            l.appendTo($('#commentErrorWrapper'));
            l.delay(3000, function() {
                l.remove();
            });
            return;
        }
        comment_content = data;
        contentTextArea.nicInstances[0].setContent('');
        $.post("/comment/create/${c.post.id}",
            {content:comment_content},
            commentAdded,
            "json");
    }

    function commentAdded(data, textStatus)  {
      if (data.flag == 1) {
          $('#comments').after(genCommentDiv(data, comment_content));
      } else {
          var l = $('<label class="error">' + data.info + '</label>');
          l.appendTo($('#commentErrorWrapper'));
          l.delay(3000, function() {
              l.remove();
          });
      }
    }

</script>
</%def>

<%def name="header()">
${header_nav()}
${rank_extra_lable(u'美文欣赏', c.post.title)}
</%def>